<template>
	<view class="body">
	<template v-if="farmInfo.farm_name">
	<view class="farmCard">
		<view class="farmCardHead">
			<view>
				<view><image src="../../../static/common/farmCardImg.png"></image></view>
				<view><text>{{farmInfo.farm_name}}</text></view>
			</view>
			<view >
				<image :src="QRcodeImage"></image>
			</view>
		</view>
		<view class="farmCardBottom">
			<view><text>养殖户名</text><text>联系方式</text><!-- <text>地址</text> --><text>禁养区</text><text>存栏</text><text>栏舍面积</text><text>动物防疫检验合格证</text></view>
			<view><text>{{farmInfo.farm_farmers}}</text><text>{{farmInfo.farm_farmers_phones}}</text><!-- <text>{{farmInfo.farm_address}}</text> --><text>{{farmInfo.farm_prohibited_area ==0 ? '是':'否'}}</text> <text>{{farmInfo.farm_seed}}<text style="color: #000000;">头</text> </text> <text>{{farmInfo.farm_total_area}}<text style="color: #000000;">亩</text></text> <text>{{farmInfo.farm_certificate ==0 ? '有':'无'}}</text></view>
		</view>
	</view>
		
	<template v-if="role == 'government'">
	<view class="carRegister">
		<view class="carRegisterHead">
			<image src="../../../static/common/car.png"></image><text>车辆备案</text>
		</view>
		<template v-if="carList">
		<block v-for="(item,index) in carList" :key="index">
		<view class="carNumNav" @tap="toCarNum(index)" >>>></view>
		<view class="farmCardBottom borderTop">
			<view><text>车牌号</text><text>所属机构</text><text>在线状态</text><text>实时运输</text></view>
			<view><text>{{carList[index].license_plate||'无'}}</text><text>{{carList[index].equipment_affiliate||'无'}}</text><text>{{carList[index].online_state||'离线'}}</text> <text>{{carList[index].dead_weight_capacity||'0'}}KG</text></view>
		</view>
		</block>
		</template>
		<template v-else>
			<no-thing style="height: 40vh;"></no-thing>
		</template>
		<view  @tap="toFaecesDispose" style="padding-top: 10rpx; height: 150rpx;">
			<view class="guideBut">
			<image src="../../../static/productionAdmin/guide.png"></image>
			<text>粪污指导</text>
		</view> </view>
		</view>
		</template>
		</template>
		<template v-else>
			
		</template>
	</view>
	
</template>
<script>
	import noThing from"../../../components/common/no-thing.vue"
	export default {
		components:{
			noThing
		},
		data(){
			return {
			      farmId:'',
				  farmInfo:'',
				  QRcodeImage:'',
				  carList:'',
				  role:''
				   };
		},
		onLoad(option) {
			this.farmId = option.farmId;
		},
		onReady() {
			this.role = this.User.userRight.name;
			if (this.role == "government") {
			this.getFarmInfo();
			this.getQRcode();
			//获取养殖签约车辆信息
			this.getCarInfo()
			}
			else{
				this.getFarmInfo();
				this.getQRcode();
			}
			
		},
		methods:{
			//获取二维码
			getQRcode(){
				// console.log(this.farmId)
				uni.request({
					url:this.confige.webUrl+"/aquaculture/getIdErc",
					data:{
						farm_id:this.farmId
					},
					header:{
						'X-Token':this.User.token
					},
					success: (res) => {
						// console.log(res)
						this.QRcodeImage = res.data.result[0].date
					}	
				})
			},
			//前往粪污指导
			toFaecesDispose(){
				uni.navigateTo({
					url:"governmentFaecesDispose?farmId="+this.farmId+"&farm_name="+this.farmInfo.farm_name+"&farm_farmers="+this.farmInfo.farm_farmers
				})
			},
			//查看养殖场该车运输记录
			toCarNum(index){
				let license_plate = this.carList[index].license_plate;
				uni.navigateTo({
					url:"./farmerCarNumDetails?license_plate="+license_plate+'&farmId='+this.farmId
				})
			},
			//获取养殖签约车辆信息
			getCarInfo(){
				console.log(this.farmId)
				uni.request({
					url:this.confige.webUrl+"/filing/selectZfCarInfo",
					header:{
						'X-Token':this.User.token
					},
					data:{
						farm_id:this.farmId
					},
					success: (res) => {
						console.log(res)
					   let list = res.data.result;
					   let arr = [];
					   for(let i=0;i<list.length;i++){
						  if(list[i].license_plate){
							  arr.push(list[i])
						  } 
					   }
					   console.log(arr)
					   this.carList = arr;
					}
				})
			},
			//查询养殖场信息
			getFarmInfo(){
				uni.request({
					url:this.confige.webUrl+"/aquaculture/FarmFiles",
					data:{
						farm_id:this.farmId
					},
					header:{
						'X-Token':this.User.token
					},
					success: (res) => {
						console.log(res)
						this.farmInfo = res.data.result[0];
					}
				})
			}
		}
	}
</script>

<style lang="less">
	@import "../../../common/global.less";
 page{ 
 background-color:@backcolor;
 }
 .borderTop{ 
	 border-bottom: 2rpx solid #f4f4f4;
	 }
 .body{ 
 width:94%;
 margin: auto; 
 }
 //顶部卡片
 .farmCard{
	 background-color: #FFFFFF;
	 margin-top: 50rpx;
	 border-radius:45rpx 45rpx 0rpx 0rpx;
	 //卡片上面样式
.farmCardHead{
	background-image:url(../../../static/common/farmCard.png);
	background-repeat:no-repeat;
	background-size: 100% 100%;
	height:250rpx;
	display:flex;
	justify-content: space-between;
	//左边
	>view:nth-of-type(1){
		color: #FFFFFF;
		display: flex;
		align-items: center;
		width: 450rpx;
		height:150rpx;
		image{ 
		height: 70rpx;
		width: 70rpx;
		margin-left: 30rpx;
		margin-top: 15rpx;
		}
		>view:nth-of-type(2){
			margin-left: 10rpx;
			font-size: 32rpx;font-weight: bold;
		}
	}
	//右边二维码
	>view:nth-of-type(2){
		display: flex;
		justify-content: center;
		align-items: center;
		height: 230rpx;
		width: 200rpx;
		image{ 
		background-color: #FFFFFF;
		width:150rpx;
		height:150rpx;
		}
	}
 }
}
.carNumNav{
	font-size: 30rpx;
	font-weight: bold;
	color: #00aaff;
	text-align: right;
	margin-right: 10rpx;
}
.farmCardBottom{
	width: 98%;
	margin-left: 2%;
	min-height:200rpx;
	margin-top: 20rpx;
	display: flex;
	padding-bottom: 20rpx;
	padding-top: 10rpx;
	flex-direction:row;
	>view{
		display: flex;
		flex-direction: column;
	}
	>view:nth-of-type(1){
		width:44%;
		text{
			color: #000000;
			font-size: 30rpx;
			text-align:left;
			border-right: 5rpx solid #CFCFCF;
			padding-right: 20rpx;
			margin-top: 20rpx;
		}
	}
	>view:nth-of-type(2){
		width:56%;
		text{
			
			
		color: #7E7E7E;
		font-size: 30rpx;
		padding-left: 20rpx;
		text-align:left;
		margin-top: 20rpx;
		overflow: hidden;
		white-space:nowrap;
		text-overflow: ellipsis;
		}	
	}
 }
//生猪车辆备案
.carRegister{
     background-color: #FFFFFF;
  .carRegisterHead{
	  height: 70rpx;
	  display: flex;align-items: center;
	    image{ 
		height: 50rpx;
		width: 50rpx;
		margin-left: 30rpx;
		}
		text{
			font-size: 32rpx;font-weight: bold;
			margin-left: 20rpx;
		}
  }
  .carOwner{ width:94%; margin:10rpx auto; border-top: 1rpx solid #d3d3d3;}
}
//指导按钮
.guideBut{
image{ 
width:90rpx;
height: 90rpx;
}
text{ font-size: 35rpx;margin-left: 20rpx;}
background: linear-gradient(to bottom, #F9DFAC, #F79B49);
// position: fixed;
// bottom: 0;
margin: auto;
color: #FFFFFF;
display: flex;
align-items: center;
justify-content: center;
width: 600rpx;
height: 130rpx;
border-radius: 20rpx;
}
</style>
